package com.wanglibao.woodtrade.woodtrade.ui.activity;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.wanglibao.woodtrade.woodtrade.R;
import com.wanglibao.woodtrade.woodtrade.config.NetConfig;
import com.wanglibao.woodtrade.woodtrade.entity.AboutUs;
import com.wanglibao.woodtrade.woodtrade.jsonrpc.JsonRPCAsyncTask;
import com.wanglibao.woodtrade.woodtrade.model.impl.UserImpl;

import butterknife.Bind;
import butterknife.ButterKnife;
/*关于我们界面*/

public class AboutUsActivity extends BaseActivity {
    @Bind(R.id.imgv_about_us)
    ImageView mImgvAboutUs;
    @Bind(R.id.tv_about_us)
    TextView mTvAboutUs;
    @Bind(R.id.rl_about_us)
    RelativeLayout mRlAboutUs;
//    ==========================
    AboutUs mAboutUs = null;
    Gson mGson = new Gson();
    Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            if (msg.arg2 != 2) {
                if (msg.arg1 == NetConfig.TaskId.aboutUs) {
                    mAboutUs = mGson.fromJson(msg.obj.toString(), AboutUs.class);
                }
            }

            return false;
        }
    });


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_us);
        ButterKnife.bind(this);
        if (Build.VERSION.SDK_INT >= 19) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {
            rl_common_title.setPadding(0, 0, 0, 0);
        }
        tvTitle.setText("关于我们");
        tvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        PackageManager packageManager = this.getPackageManager();
        PackageInfo packageInfo = null;
        try {
            packageInfo = packageManager.getPackageInfo(this.getPackageName(),0);
            String versionName = packageInfo.versionName;
            mTvAboutUs.setText("好木网 V "+versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

    }

    public void NetWorking() {
        JsonRPCAsyncTask jsonRPCAsyncTask = new JsonRPCAsyncTask(this, NetConfig.SERVER + NetConfig.TYPE_USER,
                NetConfig.aboutUs, mHandler,
                "jsonObject", NetConfig.TaskId.aboutUs, new Object[]{new UserImpl(this).getUser().token});
        jsonRPCAsyncTask.execute(new Void[]{});
    }
}
